package com.example.housekeeping.controller;

import com.example.housekeeping.pojo.dto.ServeItemAddNewDTO;
import com.example.housekeeping.pojo.dto.ServeKindsAddNewDTO;
import com.example.housekeeping.pojo.dto.ServeKindsUpdateDTO;
import com.example.housekeeping.pojo.entity.ServeKinds;
import com.example.housekeeping.pojo.vo.ServeKindsListItemVO;
import com.example.housekeeping.pojo.vo.ServeKindsStandardVO;
import com.example.housekeeping.service.ServeKindsService;
import com.example.housekeeping.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import javax.validation.Valid;
import java.util.List;

/**
 * 服务种类(ServeKinds)表控制层
 *
 * @author bob
 * @since 2023-03-30 14:26:07
 */
@Slf4j
@RestController
@RequestMapping("/serveKinds")
@Api(tags = "09.服务种类表控制模块")
public class ServeKindsController {
 @Autowired
 private  ServeKindsService serveKindsService;

    public ServeKindsController() { log.debug("创建控制器类对象ServeItemController"); }

    @PostMapping("/add-new")
    @ApiOperation("添加类别")
    @ApiOperationSupport(order = 100)
    public JsonResult<Void> addnew(@Valid @RequestBody  ServeKindsAddNewDTO serveKindsAddNewDTO){
        log.debug("开始处理【添加类别】的请求，参数：{}", serveKindsAddNewDTO);
        serveKindsService.addNew(serveKindsAddNewDTO);
        return JsonResult.ok();
    }
    @PostMapping("/{id:[0-9]+}/delete")
    @ApiOperation("根据ID删除类别")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "类别ID", required = true, dataType = "long")
    })
    public JsonResult<Void> delete(@PathVariable @Range(min = 1, message = "请提交有效的ID值！") Long id) {
        log.debug("开始处理【根据ID删除类别】的请求，参数：{}", id);
        serveKindsService.deleteById(id);
        return JsonResult.ok();
    }
    @PostMapping("/{id:[0-9]+}/update")
    @ApiOperation("修改类别详情")
    @ApiOperationSupport(order = 300)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "类别ID", required = true, dataType = "long")
    })
    public JsonResult<Void> updateInfoById(@PathVariable @Range(min = 1, message = "请提交有效的ID值！") Long id,
                                           @Valid ServeKindsUpdateDTO serveKindsUpdateDTO) {
        log.debug("开始处理【修改类别详情】的请求，ID：{}，新数据：{}", id, serveKindsUpdateDTO);
        serveKindsService.updateById(id, serveKindsUpdateDTO);
        return JsonResult.ok();
    }
    @GetMapping("/{id:[0-9]+}")
    @ApiOperation("根据ID查询类别详情")
    @ApiOperationSupport(order = 410)
    public JsonResult<ServeKindsStandardVO> getStandardById(
            @PathVariable @Range(min = 1, message = "请提交有效的ID值！") Long id) {
        log.debug("开始处理【根据ID查询类别详情】的请求，参数：{}", id);
        ServeKindsStandardVO queryResult = serveKindsService.getStandardById(id);
        return JsonResult.ok(queryResult);
    }
    @GetMapping("/list-by-parent")
    @ApiOperation("查询所有类别的业务")
    @ApiOperationSupport(order = 420)
    public JsonResult<List<ServeKindsListItemVO>> list(Long parentId) {
        log.debug("开始处理【根据父级类别查询子级类别列表】的业务，参数：{}", parentId);
        List<ServeKindsListItemVO> list = serveKindsService.list();
        return JsonResult.ok(list);
    }



}






